package 分类.链表;

public class 相交链表 {
    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        ListNode p1,p2;
        p1=headA;
        p2=headB;
        while (p1!=p2){
            if(p1==null) p1.next=headB;
            else p1=p1.next;
            if(p2==null) p2.next=headA;
            else p2=p2.next;
        }
        return p1;
    }
}
